package com.mt.api.modules.manager.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.mt.api.core.page.PageFactory;
import com.mt.api.modules.domain.AppCustomerBill;
import com.mt.api.modules.domain.bo.CustomerBillPageBo;
import com.mt.api.modules.domain.dto.CustomerBillStatDto;
import com.mt.api.modules.manager.ICustomerBillManager;
import com.mt.api.modules.mapper.CustomerBillMapper;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @Author: plover
 * @Date: 2022/04/28 15:44
 * @Description:
 */
@Component
public class CustomerBillManagerImpl extends ServiceImpl<CustomerBillMapper, AppCustomerBill> implements ICustomerBillManager {
    @Override
    public Page<AppCustomerBill> getCustomerBillPage(CustomerBillPageBo bo) {
        Page page = PageFactory.defaultPage(bo);
        LambdaQueryWrapper<AppCustomerBill> wrapper = Wrappers.lambdaQuery();
        wrapper.eq(AppCustomerBill::getCustomerId, bo.getCustomerId())
                .orderByDesc(AppCustomerBill::getId);
        return baseMapper.selectPage(page, wrapper);
    }

    @Override
    public List<CustomerBillStatDto> getCustomerBillStat(Integer customerId) {
        return baseMapper.getCustomerBillStat(customerId);
    }

    @Override
    public List<AppCustomerBill> getListByBrandId() {
        LambdaQueryWrapper<AppCustomerBill> wrapper = Wrappers.lambdaQuery();
        return baseMapper.selectList(wrapper);
    }

    @Override
    public AppCustomerBill getByBusinessIdAndType(Integer businessId, Integer type) {
        LambdaQueryWrapper<AppCustomerBill> wrapper = Wrappers.lambdaQuery();
        wrapper.eq(AppCustomerBill::getBusinessId, businessId)
                .eq(AppCustomerBill::getType, type)
                .last("limit 1");
        return baseMapper.selectOne(wrapper);
    }

}
